//
//  UserTool.m
//  SmallDay
//
//  Created by new-1020 on 2017/4/26.
//  Copyright © 2017年 com.xiaorizi. All rights reserved.
//

#import "UserTool.h"

@implementation UserTool
//+(void)loginInWithUid:(NSString *)uid {
//    NSUserDefaults * userdfaults = [NSUserDefaults standardUserDefaults];
//    [userdfaults setObject:uid forKey:@"user_id"];
//}
+(BOOL)isLogin{
    NSUserDefaults * userdfaults = [NSUserDefaults standardUserDefaults];
    NSDictionary * dic = [userdfaults objectForKey:@"userInfo"];
    if (dic) {
        return YES;
    }else {
        return NO;
    }
}

+(void)saveTheUserInfo:(NSDictionary *)info {
    NSUserDefaults * userdfaults = [NSUserDefaults standardUserDefaults];
    [userdfaults setObject:info forKey:@"userInfo"];
    [[NSUserDefaults standardUserDefaults]synchronize];
}

+(UserModel *)getTheUserModel {
    NSUserDefaults * userdfaults = [NSUserDefaults standardUserDefaults];
    NSDictionary * dic = [userdfaults objectForKey:@"userInfo"];
    UserModel * model = [[UserModel alloc]init];
    if (!dic) {
        NSLog(@"没有登陆过的用户");
        return model;
    }
    [model setValuesForKeysWithDictionary:dic];
    return model;
}

+(void)loginOut {
    NSUserDefaults * userdfaults = [NSUserDefaults standardUserDefaults];
    [userdfaults removeObjectForKey:@"userInfo"];
    [[NSUserDefaults standardUserDefaults]synchronize];
}


+(void)LoginWithAC:(NSString *)ac pwd:(NSString*)pwd block:(void(^)(BOOL))block{
    NSDictionary * dic = @{
                           @"phone" : ac,
                           @"pwd" : pwd
                           };
    [WYNetTool GET_Urlstring:LoginUrl parameters:dic success:^(id responseObject) {
        NSLog(@"%@",responseObject);
        if (SuccessCode) {
            NSDictionary * dic = responseObject[@"data"];
            [self saveTheUserInfo:dic];
            if (block) {
                block(YES);
            }
        } else {
            [Apputil showError:responseObject[@"msg"]];
            if (block) {
                block(NO);
            }
        }
    } fail:^(id error) {
        if (block) {
            block(NO);
        }
    }];
}

@end
